var tools = {};

tools.parseUrl = function(url){ 
    var r = {
        protocol: /([^\/]+:)\/\/(.*)/i,
        host: /(^[^\:\/]+)((?:\/|:|$)?.*)/,
        port: /\:?([^\/]*)(\/?.*)/,
        pathname: /([^\?#]+)(\??[^#]*)(#?.*)/
    };
    var tmp, res = {};
    res["href"] = url;
     for (var p in r) {
        tmp = r[p].exec(url);
          res[p] = tmp[1];
             url = tmp[2];
             if (url === "") {
                   url = "/";
      
    }
    if (p === "pathname") {
          res["pathname"] = tmp[1];
          res["search"] = tmp[2];
          res["hash"] = tmp[3];
      
    }    
  }
  return res; 
};
tools.url_to_host = function(url){
  var ret = tools.parseUrl(url);
  return  ret.protocol + '//'+ret.host;
};
tools.isnull = function (str) {
  if ((!str) || (typeof (str) == "undefined") || (str == null) || (str == 0)) {
    return true;
  } else {
    return false;
  }
};
module.exports = tools;